<?php
error_reporting(E_ALL ^ E_DEPRECATED);
?>
<?php
	include "dbconnect.php";

	//获取当前页数，没有就是第一页
	$page = isset($_GET['page'])?intval($_GET['page']):1;
//每页的留言数目
	$each_page = 10;
//留言总数
	$res = mysql_query("SELECT COUNT(*) FROM guestbook WHERE 1=1");
	$total = mysql_result($res, 0);

	//计算总得页数
	$total_page = ceil($total/$each_page);
	//计算页数，使得页数落在1〜总页数之间
	$page = ($page<0)?1:$page;
	$page = ($page>$total_page)?$total_page:$page;
	//根据真实页数算偏移量
	$offset = ($page-1)*$each_page;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言板</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<style>
.copyright
{
 font: normal 16px/normal "Times New Roman", Times, serif;
 color: rgba(255,255,255,1);
}
.enjoy-css {
  display: inline-block;
  -webkit-box-sizing: content-box;
  -moz-box-sizing: content-box;
  box-sizing: content-box;
  padding: 10px 20px;
  border: 1px solid #b7b7b7;
  -webkit-border-radius: 3px;
  border-radius: 3px;
  font: normal 16px/normal "Times New Roman", Times, serif;
  color: rgba(0,142,198,1);
  -o-text-overflow: clip;
  text-overflow: clip;
  background: rgba(252,252,252,1);
  -webkit-box-shadow: 2px 2px 2px 0 rgba(0,0,0,0.2) inset;
  box-shadow: 2px 2px 2px 0 rgba(0,0,0,0.2) inset;
  text-shadow: 1px 1px 0 rgba(255,255,255,0.66) ;
  -webkit-transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
  -moz-transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
  -o-transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
  transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
}
     
 </style>
<body  style="background-image : url(images/bg.jpg);background-repeat : repeat-x;background-attachment: fixed">
<div align="right"><a href="http://yyjc.oschina.mopaas.com/think/">新版留言板入口</a><a href="login.html">管理员登陆</a></div>
<div align="center">
<h3>留言板</h3>
</div>
 <div align="center" >
 <form name="FormName" method="post" action="finish.php">
    <input type="hidden" name="act" value="write">
	  <ul><input name="name" class="enjoy-css" placeholder="留下你的大名哦！" type="text" id="name" size="25" maxlength="10"></ul>
	  <ul>是否公开：<input name="ni" type="radio"  value="1" checked>
     是
    <input name="ni" type="radio"  value="0">
     否 <span class="whitefont">（公开后会在下面显示，否则只有本人才能看到哦！）</span> </td> </ul>   
		<ul><textarea class="enjoy-css" placeholder="欢迎来到我的留言板，说点什么吧！" name="comment" cols="80" rows="6" id="comment"></textarea></ul>
	 <ul> <input name="submit" class="myButton" type="submit" id="submit" value=" 提交留言 "></ul>
</form>
</div>
 <div align="center">
 <table width="80%" border="0" cellpadding="4" cellspacing="1">
  <tr>
<td colspan="2" class="HeaderRow">留言列表
	(<?php echo sprintf("/",$total, $page, $total_page) ?>)</td>
  </tr>
<?php
	if($total)
	{
		//存在留言&#35760;&#24405;
		$sql = "SELECT * FROM guestbook WHERE ni=1
			  ORDER BY postdtm DESC limit $offset, $each_page";
		$res = mysql_query($sql);
		$i = 0;

		//遍&#21382;内容&#36755;出
		while($row = mysql_fetch_object($res))
		{
			//循&#29615;&#36755;出双色表格
			$tmp = ($i++)%2;
?>
  <tr>
   <td width="10%"  align="center" valign="top" class="InputRow<?php echo $tmp ?>">
	<b><?php echo ($row->name) ?></b>
    <br>
    <br>
   </td>
   <td width="75%" valign="top" class="InputRow<?php echo $tmp ?>">
	<!-- 正文内容 -->
	<?php echo $row->comment ?>
	</td>
  <td width="15%" align="center" valign="top" class="InputRow<?php echo $tmp ?>">
	<!-- 正文内容 -->
	<?php echo $row->postdtm ?>
	</td>
  </tr>
<?php } ?>
<?php }else{ ?>
  <tr><td colspan="2" class="SubTitleRow" align="center">
	<b>留言内容不存在!</b></td></tr>
<?php } ?>

  <tr width="100%" align="center">
   <td colspan="3">
	<?php
		if($page>1){
			//如果&#39029;数大于1，&#21017;激活&#26174;示“前一&#39029;”的按&#38062;
	?>
	    <input type="button" class="bt1" value="上一页"
			onClick="location.href='?page=<?php echo $page-1 ?>'">
	<?php
		}else{
			//&#36825;里非激活&#26174;示“前一&#39029;”的按&#38062;
	?>
	    <input type="button" class="bt1" disabled value="上一页">
	<?php } ?>

	 &nbsp;

	<?php
		if($page<$total_page){

	?>
		<input type="button" class="bt1" value=" 下一页"
			onClick="location.href='?page=<?php echo $page+1 ?>'">
	<?php
		}else{
	?>
	    <input type="button" class="bt1" disabled value=" 下一页">
	<?php } ?>

   </td>
  </tr>
</table>
<br>
<br>
</div>
<div align="center">
<span class="whitefont">CopyRight 2014-2015 <a href="https://yanyu-dyh.rhcloud.com/">@虎哥style</a></span>
</div>
</body>
</html>
